/***************************************************************************
 *   Copyleft 2006-2007 by												   *
 *	 Iwanicki Krzysztof													   *
 *   <gamma.mini.pw.edu.pl/~iwanickik>									   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 ***************************************************************************/
#ifndef __BEZIER_SURFACE_H__
#define __BEZIER_SURFACE_H__

#include <vector>
#include "./Mesh.h"
#include "../../../Utils/DynamicArray.h"
#include "../Curves/BezierCurve.h"

typedef DynamicArray<BezierCurve*> BezierCurveList;

class BezierSurface: public Mesh {
protected:
	struct Float4 {
		cFloat mValues[4];
	};

	typedef DynamicArray<Float4> BasisList;

	BasisList mHorizontalBasis;
	BasisList mVerticalBasis;
	BezierCurveList	mHorizontalCurves;
	BezierCurveList	mVerticalCurves;
	cBool mSurfacesVisible;

	cVoid CalculateSurface(cInt i, cInt j);
	virtual cVoid CalculateBasis();
	virtual cVoid CalculateSurface();
public:

    /**************************************************************
    * Constructors                                                *
    ***************************************************************/
    BezierSurface();
    ~BezierSurface(); 
        
    /**************************************************************
    * Operators                                                   *
    ***************************************************************/


    /**************************************************************
    * Other helpful functions                                     *
    ***************************************************************/
	cVoid CreateSurface(AbstractCurve* curve1, AbstractCurve* curve2);
	virtual cChar* GetName();
	virtual cVoid DisplayInfo(Renderer& renderer);
	virtual cVoid Render(Renderer& renderer, Matrix4D& matrix, ProjectionPlane& plane);
	virtual cVoid Render(Renderer& renderer, Matrix4D& matrix, ProjectionPlane& plane, cWinColor color);

	virtual cVoid ChangeU(cInt iU);
	virtual cVoid ChangeV(cInt iV);
	virtual cVoid UpdateMeshPoint(cInt iRow, cInt iCol, Point4D point);
	cVoid SwitchSurfaceVisibility();
	virtual cVoid SwitchPeriodic();
	virtual cVoid SetPeriodic(cBool bPeriodic);

	virtual TiXmlElement* Serialize(TiXmlElement* parent);
};                                                                 

#endif // __BEZIER_SURFACE_H__